package cn.clementine.core.crud;

import cn.clementine.core.entity.db.DatabaseInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

@org.springframework.stereotype.Repository
public interface DataBaseCrud extends JpaRepository<DatabaseInfo,Long> {
    // 根据数据库名称查询
    // 根据数据库名称查询
    @Query("SELECT d FROM DatabaseInfo d WHERE d.db_name = ?1")
    List<DatabaseInfo> findByDbName(String dbName);

    // 根据用户名和密码查询
    @Query("SELECT d FROM DatabaseInfo d WHERE d.username = ?1 and d.password = ?2")
    List<DatabaseInfo> findByUsernameAndPassword(String username, String password);

    // 根据数据库类型查询
    @Query("SELECT d FROM DatabaseInfo d WHERE d.db_type = ?1")
    List<DatabaseInfo> findByDbType(String dbType);

    // 自定义SQL查询
    @Query("SELECT d FROM DatabaseInfo d WHERE d.db_ip = ?1")
    List<DatabaseInfo> findByIp(String ip);
}
